/**
 * author:Administrator
 * date:2011-9-7
 */
package com.roc.page;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.roc.util.Constance;
import com.roc.util.MyPageCount;

/**
 * @author Administrator
 *
 */
@Component
public abstract class PaginationBaseAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 567939096481807159L;
	protected final static String CURRENT_PAGE = "currentPage";
	protected final static String TOTAOL_PAGE = "totalPage";
	protected final static String SEARCH_RS_LIST = "searchRsList";
	protected final static String SEARCH_SESSION_BEAN_MERCHANT = "search_session_merchant";
	protected final static String SEARCH_SESSION_BEAN_MERCHANT_POWER = "search_session_merchant_power";
	protected final static String SEARCH_SESSION_BEAN_MERCHANT_POWER_YJ = "search_session_merchant_power_yj";
	protected final static String SEARCH_SESSION_BEAN_ESTRN_LOG_YJ = "search_session_bean_estrn_log_yj";
	protected final static String SEARCH_SESSION_BEAN_ESTRN_HIS = "search_session_bean_estrn_his";
	protected final static String SEARCH_SESSION_BEAN_ESTRN_HIS_RISK = "search_session_bean_estrn_his_risl";
	protected final static String SEARCH_SESSION_BEAN_SYS_LOG = "search_session_sys_log";
	protected final static String SEARCH_SESSION_BEAN_PROFIT_MODEL = "search_session_bean_profit_model";
	protected final static String SEARCH_SESSION_BEAN_ORG = "search_session_bean_org";
	protected final static String SEARCH_SESSION_BEAN_MERCHANT_MANAGE = "search_session_merchant_power_manage";
	protected final static String SEARCH_SESSION_BEAN_FINANCE = "search_session_bean_finance";
	protected final static String SEARCH_SESSION_BEAN_OPRATOR_CHECK = "search_session_bean_oprator_check";
	protected final static String SEARCH_SESSION_BEAN_AGENT_AUDITING_ONE = "search_session_bean_agent_auditing_one";
	protected final static String SEARCH_SESSION_BEAN_AGENT_AUDITING_TWO = "search_session_bean_agent_auditing_two";
	protected final static String SEARCH_SESSION_BEAN_AGENT_QUERY_INFO = "search_session_bean_agent_query_info";
	protected final static String SEARCH_SESSION_BEAN_AGENT_SET_INFO = "search_session_bean_agent_set_info";
	protected final static String SEARCH_SESSION_MERINFO_INFO = "search_session_merinfo_info";
	protected final static String SEARCH_SESSION_FORMAL_MERINFO_INFO = "search_session_formal_merinfo_info";
	protected final static String SEARCH_SESSION_BEAN_TERMINAL_APPLY = "search_session_bean_terminal_apply";
	protected final static String SEARCH_SESSION_BEAN_TERMINAL_SN_QUERY = "search_session_bean_terminal_sn_query";
	protected final static String SEARCH_SESSION_BEAN_TERM_SN_AGENT = "search_session_bean_term_sn_agent";
	protected final static String SEARCH_SESSION_BEAN_AGENT_SUBSIDY = "search_session_bean_agent_subsidy";

	protected final static String SEARCH_SESSION_BEAN_TERMINAL_LIST = "search_session_bean_terminal_list";
	protected final static String SEARCH_SESSION_BEAN_MERCHANT_QRT = "search_session_merchant_qry";

	protected final static String SEARCH_SESSION_BEAN_CALCU = "search_session_bean_calcu";
	protected final static String SEARCH_SESSION_BEAN_SETTING = "search_session_bean_setting";
	protected final static String SEARCH_SESSION_BEAN_HRTSETTING = "search_session_bean_hrtsetting";
	protected final static String SEARCH_SESSION_BEAN_SETTINGEXCEL = "search_session_bean_settingexcel";
	protected final static String SEARCH_SESSION_BEAN_TOTALSETTING = "search_session_bean_totalsetting";
	protected final static String SEARCH_SESSION_BEAN_REVIEWSETTING = "search_session_bean_reviewsetting";
	protected final static String SEARCH_SESSION_BEAN_FROZEN = "search_session_bean_frozen";
	protected final static String SEARCH_SESSION_BEAN_REVIEWFROZEN = "search_session_bean_reviewfrozen";
	protected final static String SEARCH_SESSION_BEAN_REVIEWUNFROZEN = "search_session_bean_reviewunfrozen";
	protected final static String SEARCH_SESSION_BEAN_UNFROZEN = "search_session_bean_unfrozen";
	protected final static String SEARCH_SESSION_BEAN_OPRATOR_QUERY = "search_session_bean_oprator_query";
	protected final static String SEARCH_SESSION_BEAN_POWER_MODEL = "search_session_bean_power_model";
	protected final static String SEARCH_SESSION_BEAN_DIAODAN = "search_session_bean_diaodan";
	protected final static String SEARCH_SESSION_BEAN_TERMINAL_QUERY = "search_session_bean_terminal_query";
	protected final static String SEARCH_SESSION_BEAN_BANKINFO_QUERY = "search_session_bean_bankinfo_query";
	protected final static String SEARCH_SESSION_BEAN_TERM_SN = "search_session_bean_term_sn";
	protected final static String SEARCH_SESSION_BEAN_TERM_SN_IMPORT = "search_session_bean_term_sn_import";
	protected final static String SEARCH_SESSION_BEAN_TERM_SN_INFO = "search_session_bean_term_sn_info";
	protected final static String SEARCH_SESSION_SERIAL_NUM_QUERY = "search_session_serial_num_query";

	protected final static String SEARCH_SESSION_BEAN_MERINFO_CHANGE = "search_session_bean_merinfo_change";
	protected final static String SEARCH_SESSION_BEAN_MERINFO_CHANGE_CHECK = "search_session_bean_merinfo_change_check";
	protected final static String SEARCH_SESSION_TERM_SN_BELONG_QUERY = "search_session_bean_term_sn_belong_query";
	protected final static String SEARCH_SESSION_TERMINAL_ALLOT_RECALL = "search_session_bean_terminal_allot_recall";
	protected final static String SEARCH_SESSION_MERINFO_ALLOAT_QUERY = "search_session_merinfo_alloat_query";
	protected final static String SEARCH_SESSION_TERMINAL_SN_EXCHANGE = "search_session_bean_termianl_sn_exchange";

	protected final static String SEARCH_SESSION_BLACK_QUERY = "search_session_black_query";
	protected final static String SEARCH_SESSION_BANK_CARD_QUERY = "search_session_bank_card_query";

	protected final static String SEARCH_SESSION_BEAN_MERINFO_CHANGE_QUREY = "search_session_bean_merinfo_change_qurey";

	protected final static String SEARCH_SESSION_BEAN_TERMINAL_LOGOUT = "search_session_bean_terminal_logout";

	protected final static String SEARCH_SESSION_MERINFO_SET_QUERY = "search_session_merinfo_set_query";

	protected final static String SEARCH_SESSION_MERINFO_BATCHEXPORT = "search_session_merinfo_batchexport";
	protected final static String SEARCH_SESSION_MERCHANT_TRANS_QUERY = "search_session_merchant_trans_query";
	protected final static String SEARCH_SESSION_MERINFO_MANAGE = "search_session_merinfo_manage";
	protected final static String SEARCH_SESSION_BIGESTRNHIS_QUERY = "search_session_bigestrnhis_query";
	protected final static String SEARCH_SESSION_ANNOUNCE_QUERY = "search_session_announce_query";

	protected final static String SEARCH_SESSION_PROFIT_SHARE_QUERY = "search_session_profit_share_query";

	protected final static String SEARCH_SESSION_PROFIT_SHARE_DETAIL_QUERY = "search_session_profit_share_detail_query";

	protected final static String SEARCH_SESSION_TID_RECORD_QUERY = "search_session_tid_record_query";
	protected final static String SEARCH_SESSION_CARDBIN_QUERY = "search_session_cardbin_query";
	protected final static String SEARCH_SESSION_SUSMERINFO_QUERY = "search_session_susmerinfo_query";

	protected final static String SEARCH_SESSION_MERCHANT_REPORT = "search_session_merchant_report";
	protected final static String SEARCH_SESSION_DAILI_MONTH = "search_session_daili_month";
	protected final static String SEARCH_SESSION_QUERY_SETTLEMENT = "search_session_query_settlement";
	protected final static String SEARCH_SESSION_QUERY_WIND_CONTROLL = "search_session_query_wind_controll";
	protected final static String SEARCH_SESSION_QUERY_CHANGE_CHECK = "search_session_query_change_check";
	protected final static String SEARCH_SESSION_QUERY_AUDIT_STATISTICS = "search_session_query_audit_statistics";
	protected final static String SEARCH_SESSION_MERINFO_REJECTED = "search_session_merinfo_rejected";

	protected final static String SEARCH_SESSION_PROFIT_SUM_QUERY = "search_session_profit_sum_query";
	protected final static String SEARCH_SESSION_PROFIT_DETAIL_QUERY = "search_session_profit_detail_query";
	protected final static String SEARCH_SESSION_PROFIT_DASUM_QUERY = "search_session_profit_dasum_query";

	protected final static String SEARCH_SESSION_MERCHANT_AGENT_AFFI = "search_session_merchant_agent_affi";
	protected final static String SEARCH_SESSION_MERCHANT_AGENT_RELA = "search_session_merchant_agent_rela";
	protected final static String SEARCH_SESSION_BLACK_LIST_QUERY = "search_session_black_list_query";
	protected final static String SEARCH_SESSION_BLACK_LIST_AUDIT = "search_session_black_list_audit";
	protected final static String SEARCH_SESSION_anency_LIST_QUERY = "search_session_anency_list_query";
	protected final static String SEARCH_SESSION_STOP_LIST_QUERY = "search_session_stop_list_query";
	protected final static String SEARCH_SESSION_RETURN_CODE_QUERY = "search_session_return_code_query";
	protected final static String SEARCH_SESSION_WHITE_LIST_QUERY = "search_session_white_list_query";
	protected final static String SEARCH_SESSION_TRANS_LIMIT_QUERY = "search_session_trans_limit_query";
	protected final static String SEARCH_SESSION_TRANS_SWITCH_QUERY = "search_session_trans_switch_query";

	protected final static String SEARCH_SESSION_ESTRN_STASTICS = "search_session_estrn_stastics";
	protected final static String SEARCH_SESSION_FREEZE_QUERY = "search_session_freeze_query";

	protected final static String SEARCH_SESSION_OPERATOR_AUTH = "search_session_operator_auth";
	protected final static String SEARCH_SESSION_OPERATOR_AUTH_CHECK = "search_session_operator_auth_check";
	protected final static String SEARCH_SESSION_UNPAY_QUERY = "search_session_unpay_query";
	protected final static String SEARCH_SESSION_UNPAY_STATEMENT_QUERY = "search_session_unpay_satement_query";
	protected final static String SEARCH_SESSION_MSG_QUERY = "search_session_msg_query";
	protected final static String SEARCH_SESSION_MAKE_MONEY_QUERY = "search_session_make_money_query";
	protected final static String SEARCH_SESSION_ORG_MONEY_QUERY = "search_session_org_money_query";
	protected final static String SEARCH_SESSION_TO_PAY_QUERY = "search_session_to_pay_query";
	protected final static String SEARCH_SESSION_ORG_PAY_QUERY = "search_session_org_pay_query";
	protected final static String SEARCH_SESSION_HANG_PAY_QUERY = "search_session_hang_pay_query";
	protected final static String SEARCH_SESSION_HANG_PAY_FREE_QUERY = "search_session_hang_pay_free_query";
	protected final static String SEARCH_SESSION_PAY_TREASURE_MANAGER = "search_session_pay_treasure_manager";
	protected final static String SEARCH_SESSION_BEAN_SNRELEASE_QUERY = "search_session_bean_SNRELEASE_query";
	protected final static String SEARCH_SESSION_RISK_RULE_QUERY = "search_session_risk_rule_query";
	protected final static String SEARCH_SESSION_TERM_INFO_DOWN_QUERY = "search_session_term_info_down_query";
	protected final static String SEARCH_SESSION_ACCOUNT_STA_QUERY = "search_session_account_sta_query";
	protected final static String SEARCH_SESSION_EXPORT_MT_QUERY = "search_session_export_mt_query";
	protected final static String SEARCH_SESSION_DEDUCTIONS_QUERY = "search_session_deductions_query";
	protected final static String SEARCH_SESSION_TMP_DEDUCTIONS_QUERY = "search_session_tmp_deductions_query";

	protected final static String SEARCH_SESSION_TO_PAY_AGAIN_QUERY = "search_session_to_pay_again_query";
	protected final static String SEARCH_SESSION_ORDER_PROCESS_QUERY = "search_session_order_process_query";
	protected final static String SEARCH_AGENCY_MCHT_SUMMARY_QUERY = "search_session_agency_mcht_summary_query";

	protected final static String SEARCH_SESSION_JUMP_MCHT_QUERY = "search_session_jump_mcht_query";
	
	protected final static String SEARCH_SESSION_ERROR_COUNT_QUERY = "search_session_error_count_query";
	
	protected final static String SEARCH_SESSION_QUERY_REVISE_LIST = "search_session_query_Revise_list";
	protected final static String SEARCH_SESSION_REVISE_MERINFO_QUERY = "search_session_revise_merinfo_query";
	protected final static String SEARCH_SESSION_MERCHANTS_CHANGE_RECORD_QUERY = "search_session_merchants_change_record_query";
 
	protected final static String SEARCH_SESSION_TBL_AREA = "search_session_tbl_area";
	protected final static String SEARCH_SESSION_TEMP_MONEY_QUERY = "search_session_temp_money_query";
	protected final static String SEARCH_SESSION_REUPLOAD_PIC_QUERY = "search_session_reupload_pic_query";
	protected final static String SEARCH_SESSION_SCAN_CODE_QUERY = "search_session_scan_code_query";
	protected final static String SEARCH_SESSION_TEMP_MERINFO_INFO = "search_session_temp_merinfo_info";
	protected final static String SEARCH_SESSION_MERINFO_TERM_DETAIL = "search_session_merinfo_term_detail";

	protected final static String SEARCH_SESSION_NO_ESTRN_MERCHANT = "search_session_no_estrn_merchant";
	protected final static String SEARCH_SESSION_WARE_HOUSE_SN_STATISTICS = "search_session_ware_house_sn_statistics";
	protected final static String SEARCH_SESSION_SN_REVOCATION = "search_session_sn_revocation";
	protected final static String SEARCH_SESSION_DAY_STASTICS = "search_session_day_stastics";
	protected final static String SEARCH_SESSION_MERAREA_INFO = "search_session_merarea_info";
	
	protected final static String SEARCH_SESSION_COMM_NUMBER_STAT = "search_session_comm_number_stat";
	protected final static String SEARCH_SESSION_TERM_VER_QUERY = "search_session_term_ver_query";
	protected final static String YSB_SEARCH_SESSION_BEAN_ESTRN_HIS = "ysb_search_session_bean_estrn_his";
	protected final static String YSB_SEARCH_SESSION_BEAN_ESTRN_LOG_YJ = "ysb_search_session_bean_estrn_log_yj";

	

	protected final static String SEARCH_SESSION_COMP_TRANS_COUNT = "search_session_comp_trans_count";
	protected final static String SEARCH_SESSION_MERYSBINFO_INFO = "search_session_merysb_info";
	protected final static String SEARCH_SESSION_ACCOUNT_BALANCE_QUERY = "search_session_account_balance_query";

	protected final static String SEARCH_SESSION_BEAN_YSBTERM_SN_QUERY = "search_session_bean_ysbterm_sn_query";

	protected final static String SEARCH_SESSION_YSBDETAIL_LIST_QUERY = "search_session_ysb_detail_list_query";
	
	protected final static String SEARCH_SESSION_SCAN_CODE_AUDIT_QUERY = "search_session_scan_code_audit_query";

	protected final static String SEARCH_SESSION_YSB_SN_STATISTICS = "search_session_ysb_sn_statistics";
	protected final static String SEARCH_SESSION_YSB_SN_STATISTICS_DETAIL = "search_session_ysb_sn_statistics_detail";
	
	protected final static String SEARCH_SESSION_YSBTERM_ACTIV_LIST_QUERY = "search_session_ysbterm_activ_list_query";
	protected final static String SEARCH_SESSION_YSB_SN_REVOCATION = "search_session_ysb_sn_revocation";
	
	protected final static String SEARCH_SESSION_YSB_TERM_SN_REPLACE = "search_session_ysb_term_sn_replace";
	protected final static String SEARCH_SESSION_YSB_TERM_SN_REP_AGENT = "search_session_ysb_term_sn_rep_agent";

	protected final static String SEARCH_SESSION_YS_BREAL_NAME_REJECT = "search_session_ys_breal_name_reject";
	
	protected final static String SEARCH_SESSION_TRANS_SUM = "search_session_trans_sum";
	
	protected final static String SEARCH_SESSION_MARGIN_RETURN = "search_session_margin_return";
 
	protected final static String RISK_YSB_SEARCH_SESSION_BEAN_ESTRN = "risk_ysb_search_session_bean_estrn";

	protected final static String RISK_YSB_SEARCH_SESSION_BEAN_ESTRN_HIS = "risk_ysb_search_session_bean_estrn_his";
	protected final static String SEARCH_SESSION_BIND_MERINFO = "search_session_bind_merinfo";

	private String currentPage = "1";
	private String totalPage = "1";
	protected List<Long> multi_sel = new ArrayList<Long>();
	protected List<String> multi_sel_str = new ArrayList<String>();
	protected List<Object> searchRsList = new ArrayList<Object>();

	// private PaginationService pageService ;

	public String execute() throws Exception {
		// initSomeDataForAction();
		// BaseSearchCondition searchCondition =
		// getSearchConditionFromSession();
		/*
		 * if (searchCondition!=null) { //Prepare the Pagination search result
		 * List again. searchRsList =
		 * pageService.searchPaginationListByCondition(searchCondition);
		 * dealWithTheListSpecially(searchRsList); currentPage =
		 * String.valueOf(searchCondition.getPagination().getCurrentPage());
		 * oldPage = currentPage; rowCount =
		 * String.valueOf(searchCondition.getPagination().getRowCount());
		 * getRequest
		 * ().setAttribute("pagination",searchCondition.getPagination());
		 * setSearchConditionToSubClass(searchCondition); }else{ //Prepare the
		 * Pagination object when Initialize. Pagination pagination = new
		 * Pagination(); pagination.setCurrentPage("1");
		 * pagination.setPageSize(StringUtils
		 * .isBlank(getInitPageSize())?"10":getInitPageSize());
		 * getRequest().setAttribute("pagination",pagination); } String
		 * session_key_sel = getKeySelFromSession();
		 * if(StringUtils.isNotBlank(session_key_sel)){ this.key_sel =
		 * getKeySelFromSession(); }
		 */
		return SUCCESS;
	}

	/**
	 * Map to the submit button which the method properties is
	 * "paginationSearch"
	 * @return action forward String
	 * @throws Exception
	 */
	public String paginationSearch() throws Exception {
		// BaseSearchCondition searchCondition =
		// getSearchConditionFromSubClass();
		/*
		 * Pagination pagination = new Pagination();
		 * pagination.setCurrentPage("1");
		 * pagination.setPageSize(StringUtils.isBlank
		 * (getInitPageSize())?"10":getInitPageSize());
		 * searchCondition.setPagination(pagination);
		 * setSearchToConditionSession(searchCondition);
		 * addMultiSelIntoSession(); searchRsList =
		 * pageService.searchPaginationListByCondition(searchCondition);
		 * dealWithTheListSpecially(searchRsList);
		 * getRequest().setAttribute("pagination"
		 * ,searchCondition.getPagination()); initSomeDataForAction(); rowCount
		 * = String.valueOf(searchCondition.getPagination().getRowCount());
		 * if(multi_sel!=null){ multi_sel.clear(); }
		 */
		return SUCCESS;
	}

	/**
	 * only to initialize the searchRsList
	 * @return action forward String
	 * @throws Exception
	 */
	public void initTheSearchRsList() throws Exception {
		// BaseSearchCondition searchCondition =
		// getSearchConditionFromSession();
		/*
		 * currentPage =
		 * String.valueOf(searchCondition.getPagination().getCurrentPage());
		 * oldPage = currentPage; rowCount =
		 * String.valueOf(searchCondition.getPagination().getRowCount());
		 * getRequest
		 * ().setAttribute("pagination",searchCondition.getPagination());
		 * searchRsList =
		 * pageService.searchPaginationListByCondition(searchCondition);
		 * dealWithTheListSpecially(searchRsList);
		 */
	}

	/**
	 * Get the search condition from Form.
	 * 
	 * @return
	 */
	protected abstract BaseSearchCondition getSearchConditionFromSubClass() throws Exception;

	/**
	 * Get the search condition from Form.
	 * 
	 * @return
	 */
	protected abstract void setSearchConditionToSubClass(BaseSearchCondition searchCondition)
			throws Exception;

	/**
	 * set the search condition into session.
	 * 
	 * @return
	 */
	protected abstract void setSearchToConditionSession(BaseSearchCondition searchCondition);

	/**
	 * Get the search condition from session.
	 * 
	 * @return
	 */
	protected abstract BaseSearchCondition getSearchConditionFromSession();

	/**
	 * if you want to deal with the list data specially,you should Override this
	 * method in your action.
	 */
	protected void dealWithTheListSpecially(List<Object> list) {

	}

	/**
	 * if you want to store the key_sel,you should Override this method in your
	 * action.
	 */
	protected String getKeySelFromSession() {
		return "";
	}

	protected String getMultiSelSessionKeyName() {
		return null;
	}

	protected abstract String getInitPageSize();

	public void setSearchRsList(List<Object> searchRsList) {
		this.searchRsList = searchRsList;
	}

	/**
	 * @return the searchRsList
	 */
	public List<Object> getSearchRsList() {
		return searchRsList;
	}

	public List<Long> getMulti_sel() {
		return multi_sel;
	}

	public void setMulti_sel(List<Long> multi_sel) {
		this.multi_sel = multi_sel;
	}

	public String getCurrentPage() {

		return currentPage;
	}

	public void setCurrentPage(String currentPage) {
		this.currentPage = currentPage;
		// getSession().put(CURRENT_PAGE_SESSION, this.currentPage);
	}

	public String getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(String totalPage) {
		this.totalPage = totalPage;
	}

	protected int calcuStart(String currentPage) {
		if (!Constance.isNotEmpty(currentPage)) {
			return 0;
		}
		int temp = Integer.parseInt(currentPage);
		return (temp - 1) * Constance.PAGE_MAX_SIZE;
	}

	protected String calcuTotalPage(int rows) {
		int tPage = MyPageCount.getTotalPages(rows, Constance.PAGE_MAX_SIZE);
		return String.valueOf(tPage);

	}

	/*
	 * protected String calcuTotalPage2(int rows){ int
	 * tPage=MyPageCount.getTotalPages(rows, Constance.PAGE_MAX_SIZE_100);
	 * return String.valueOf(tPage); }
	 */

	protected String checkCurrentPage() {
		if (!Constance.isNotEmpty(currentPage)) {
			currentPage = "1";
		}
		int cPage = Integer.parseInt(currentPage);
		if (cPage < 1) {
			currentPage = "1";
		}
		int tPage = Integer.parseInt(totalPage);
		if (cPage > tPage) {
			currentPage = totalPage;
		}
		return currentPage;
	}

	public List<String> getMulti_sel_str() {
		return multi_sel_str;
	}

	public void setMulti_sel_str(List<String> multi_sel_str) {
		this.multi_sel_str = multi_sel_str;
	}

}
